using System.Collections.Generic;
using ArmyManager.Units;

namespace ArmyManager.Strategies
{
	public class UnitComparer : IComparer<Unit.UnitTypes>
	{
		private readonly IEnumerable<Unit.UnitTypes> _unitOrdering;

		public UnitComparer(IEnumerable<Unit.UnitTypes> unitOrdering)
		{
			_unitOrdering = unitOrdering ?? new List<Unit.UnitTypes>();
		}

		public int Compare(Unit.UnitTypes x, Unit.UnitTypes y)
		{
			if (x == y) return 0;
			foreach (Unit.UnitTypes unitType in _unitOrdering)
			{
				if (x == unitType) return 1;
				if (y == unitType) return -1;
			}
			return 0;
		}
	}
}